const httpRequest = require("@/common/httpRequest.js")
import App from './App'
const copy = (value) => { //复制
	uni.setClipboardData({
		data: value, //要被复制的内容
		success: () => {
			//复制成功的回调函数
			httpRequest.toast("复制成功")
		}
	});
}
const jumpzhuye = (id) => { //进入主页
	uni.navigateTo({
		url: "/pages_homepage/zhuye?id=" + id
	})
}
const jumpurl = (url) => { 
	uni.navigateTo({
		url
	})
}
const jumpDetail = (url,id) => { 
	uni.navigateTo({
		url:url+id
	})
}
const lbtpriview = (index, arr) => { //预览图片
	var i = arr; //获取当前页面的轮播图数据
	//uniapp预览轮播图
	uni.previewImage({
		current: index, //预览图片的下标
		urls: i //预览图片的地址，必须要数组形式，如果不是数组形式就转换成数组形式就可以
	})
}
const callphone = (p) => { //拨打电话
	uni.makePhoneCall({
		phoneNumber: p.toString(),
		fail(err) {
			console.log("打电话失败", err);
		}
	}).catch((e) => {
		console.log(e, "失败") //用catch(e)来捕获错误{makePhoneCall:fail cancel}
	})
}
const sharevideoOrdt = (val, id) => {
	if (!httpRequest.checkIsLogin()) {
		uni.navigateTo({
			url: "/pages/login/login"
		})
		return false;
	}
	uni.navigateTo({
		url: "/pages_message/sharePersonList?type=" + val + "&id=" + id,
		fail(err) {
			console.log(err);
		}
	})
}
const returnKmUnit = (m) => {
	var v;
	if (typeof m === 'number' && !isNaN(m)) {
		if (m >= 1000) {
			v = (m / 1000).toFixed(2) + 'km'
		} else {
			v = Number(m).toFixed(2) + 'm'
		}
	} else {
		v = '0m'
	}
	return v;
}
const openAuthSetting = () => {
	let that = this;
	uni.showModal({
		title: '提示',
		content: '此功能需要获取您的位置信息，请确认授权后重启App重试',
		success: function(modalRes) {
			if (modalRes.confirm) {
				uni.openAppAuthorizeSetting({
					success: function(settingRes) {
						console.log('设置页面打开成功', settingRes);
					},
					fail: function(settingErr) {
						console.log('设置页面打开失败', settingErr);
					}
				});
			}
		}
	});
}
const getthdetail = (thbo, time) => { //获取通话记录，查看获得了/扣除了多少金币
	httpRequest.request('/api/user/getUserTh', 'GET', {
		thbo
	}).then(res => {
		console.log("获取通话记录，查看获得了/扣除了多少金币", time);
		console.log("获取通话记录，查看获得了/扣除了多少金币", res);
		let dataobj = {
			xf: res.data.user_id == uni.getStorageSync("user_id") ? true : false,
			time: time,
			xfjb: res.data.jb_num,
		}
		setTimeout(() => {
			uni.navigateTo({
				url: '/pages_message/popup?msg=' + encodeURIComponent(JSON.stringify(
					dataobj)),
				success(res) {
					console.log("跳转成功");
				},
				fail(err) {
					console.log("跳转失败",err);
				}
			})
		}, 1000)
	})
}
// #ifndef VUE3
import Vue from 'vue'
import './uni.promisify.adaptor'
import store from './store'
Vue.prototype.$store = store
Vue.config.productionTip = false
Vue.prototype.copy = copy
Vue.prototype.lbtpriview = lbtpriview
Vue.prototype.callphone = callphone
Vue.prototype.jumpzhuye = jumpzhuye
Vue.prototype.jumpurl = jumpurl
Vue.prototype.jumpDetail = jumpDetail
Vue.prototype.sharevideoOrdt = sharevideoOrdt
Vue.prototype.returnKmUnit = returnKmUnit
Vue.prototype.openAuthSetting = openAuthSetting
Vue.prototype.getthdetail = getthdetail

// 安装插件

App.mpType = 'app'
const app = new Vue({
	...App
})
app.$mount()
// #endif
// main.js
import uView from "uview-ui";
Vue.use(uView);
// #ifdef VUE3
import {
	createSSRApp
} from 'vue'
export function createApp() {
	const app = createSSRApp(App)
	return {
		app
	}
}
// #endif
Vue.use(uView);